BelongsToMany relations pivot fields are null in Livewire refresh

122

# BelongsToMany relations pivot fields are null in Livewire refresh
# just re-hydrate it, example:

// in Model
public function role(){
	return $this->belongsToMany(Role::class, "tbl_user_has_roles", "user_id", "role_id")->withPivot("some_column");
}

// in livewire component
public function hydrate(){
	$this->userRole = User::with(["role"])->where('id', $this->id)->first()->role;
}

Comments

Submit
0 Comments